﻿B4J=true
Group=Default Group\Utils
ModulesStructureVersion=1
Type=StaticCode
Version=10.3
@EndOfDesignText@

Sub Process_Globals
	
End Sub

'' 返回成功结果
Public Sub Success(resp As ServletResponse,msg As String,data As Object)
	Dim mp As Map
	mp.Initialize
	mp.Put("code",200)
	mp.Put("msg",msg)
	mp.Put("data",data)
	''----
	Dim jsn As JSONGenerator
	jsn.Initialize(mp)
	''----
	resp.Status=200
	resp.CharacterEncoding="utf8"
	resp.ContentType="application/json"
	resp.Write(jsn.ToString)
End Sub

'' 返回失败结果
Public Sub Error(resp As ServletResponse,msg As String,data As Object)
	Dim mp As Map
	mp.Initialize
	mp.Put("code",500)
	mp.Put("msg",msg)
	mp.Put("data",data)
	''----
	Dim jsn As JSONGenerator
	jsn.Initialize(mp)
	''----
	resp.Status=500
	resp.CharacterEncoding="utf8"
	resp.ContentType="application/json"
	resp.Write(jsn.ToString)
End Sub

'' 返回自定义结果
Public Sub Custom(resp As ServletResponse,code As Int, msg As String,data As Object)
	Dim mp As Map
	mp.Initialize
	mp.Put("code",code)
	mp.Put("msg",msg)
	mp.Put("data",data)
	''----
	Dim jsn As JSONGenerator
	jsn.Initialize(mp)
	''----
	resp.Status=401
	resp.CharacterEncoding="utf8"
	resp.ContentType="application/json"
	resp.Write(jsn.ToString)
End Sub
